import router from "../router";

var routerTitle = "",
  siteTitle = "";

const setTitle = () => {
  let title = "";
  if (!routerTitle && !siteTitle) {
    title = "加载中...";
  } else if (routerTitle && !siteTitle) {
    title = routerTitle;
  } else if (!routerTitle && siteTitle) {
    title = siteTitle;
  } else {
    title = `${routerTitle} - ${siteTitle}`;
  }
  document.title = title;
};

function setRouterTitle(title) {
  routerTitle = title;
  setTitle();
}

function setSiteTitle(title) {
  siteTitle = title;
  setTitle();
}

export { setRouterTitle, setSiteTitle };
